package com.microinvest.util;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import java.util.Date;
import java.util.Map;

//此工具作用为获取token令牌和解析token令牌
//
public class JwtUtil {
    //token密钥生成
    private static final String KEY="haveagoodday";

    public static String genToken(Map<String,Object>claims){
        return JWT.create()
                .withClaim("claims",claims)
                .withExpiresAt(new Date(System.currentTimeMillis()+1000*60*60*5))
                .sign(Algorithm.HMAC256(KEY));//指定算法配置密钥
    }
    //解析token密钥
    public static Map<String,Object> parseToken(String token){
        return JWT.require(Algorithm.HMAC256(KEY))
                .build()
                .verify(token)
                .getClaim("claims")
                .asMap();
    }
}
